//
// Created by gyc on 2020/10/19.
//
#include "../../common.h"

class Solution {
private:
    string disposeStr(string &s) {
        int fast = 0, slow = 0;
        while (fast < s.size()) {
            if (s[fast] != '#') {
                s[slow++] = s[fast];
            } else {
                if (slow > 0) {
                    --slow;
                }
            }
            ++fast;
        }
        return s.substr(0, slow);
    }

public:
    bool backspaceCompare(string S, string T) {
        return disposeStr(S) == disposeStr(T);
    }
};

int main() {

    cout << Solution().backspaceCompare("ab##", "c#d#");
}